import axios from 'axios'
import qs from 'qs'
const URL = 'http://www.lihanxin.top:7500'

//获取任务列表
export const getTodos = () => {
  return axios({
    method: 'GET',
    url: `${URL}/getTodos`,
  })
}

//新增任务列表
export const addTodo = (name) => {
  return axios({
    method: 'POST',
    url: `${URL}/add`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({
      name,
    }),
  })
}

//修改任务状态
export const updateTodo = (id, isDone) => {
  return axios({
    method: 'POST',
    url: `${URL}/update`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({
      id,
      isDone,
    }),
  })
}

//批量修改任务状态
export const updateTodos = (ids, isDone) => {
  return axios({
    method: 'POST',
    url: `${URL}/updateCheck`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({
      ids,
      isDone,
    }),
  })
}

//删除任务
export const deleteTodo = (id) => {
  return axios({
    method: 'POST',
    url: `${URL}/delete`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({
      id,
    }),
  })
}

//批量删除任务
export const deleteTodos = (ids) => {
  return axios({
    method: 'POST',
    url: `${URL}/deleteCheck`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({
      ids,
    }),
  })
}
